<?php
/**
 * Create by Phpstorm
 * User: Peco
 * Date: 2019/12/19
 * Time: 16:07
 */

namespace App\Http\Controllers\Api\Auction;

use App\Http\Controllers\Api\BaseAdminController;
use App\Http\Requests\Auction\AuctionGoodsPageRequest;
use App\Http\Requests\Auction\AuctionRecordPageRequest;
use App\Http\Transformers\Auction\AuctionGoodsPageTransformer;
use App\Http\Transformers\Auction\AuctionRecordPageTransformer;
use App\Repositories\AuctionRepository;

class AuctionController extends BaseAdminController
{
    /**
     * @var AuctionRepository
     */
    protected $auctionRepository;

    /**
     * AuctionController constructor.
     * @param AuctionRepository $auctionRepository
     */
    public function __construct(AuctionRepository $auctionRepository)
    {
        $this->auctionRepository = $auctionRepository;
    }

    /**
     * 拍卖纪录分页列表
     * @param AuctionRecordPageRequest $request
     * @return \Dingo\Api\Http\Response
     */
    public function auctionRecordPage(AuctionRecordPageRequest $request){
        $limit = $request->get('limit');
        $data = $request->all(['name', 'goodsName', 'goodsAuctionInfoStatusOptions', 'auctionStatus']);

        $page = $this->auctionRepository->auctionRecordPageRepository($data, $limit);

        return $this->response->paginator($page, new AuctionRecordPageTransformer());
    }

    /**
     * 拍卖商品信息
     * @param AuctionGoodsPageRequest $request
     * @return \Dingo\Api\Http\Response
     */
    public function auctionGoodsPage(AuctionGoodsPageRequest $request){
        $limit = $request->get('limit');
        $data = $request->all(['status', 'goodsName', 'goodsType', 'categoryId']);

        $page = $this->auctionRepository->auctionGoodsPageRepository($data, $limit);

        return $this->response->paginator($page, new AuctionGoodsPageTransformer());
    }
}
